package main

import "fmt"

func main() {
	//map的定义
	//map[键类型]值类型
	var name map[int]string
	//在map中不能cap函数，只能使用len函数
	fmt.Println(name)
	//第二种 4代表添加的容量
	name1 := make(map[int]string, 4)
	fmt.Println(name1)
	//赋值
	//键是唯一的，值是可以重复的
	//map是无序的
	name1[1] = "刘谦"
	name1[2] = "刘"
	name1[3] = "刘谦1"
	name1[4] = "刘谦2"
	name1[5] = "刘谦3"
	name1[6] = "刘谦4"
	name1[0] = "刘谦5"
	fmt.Println(name1)
	//初始化
	name2 := map[int]string{0: "a", 1: "b", 2: "c", 3: "d", 4: "e", 5: "f", 6: "g"}
	fmt.Println(name2[1])
	fmt.Println(name2)
	//键和值
	//map中，键的类型必须是基本数据类型，不能是切片和函数类型
	//map是无序的
	//map是自动扩容的
	name3 := map[string][3]int{}
	name3["张三"] = [3]int{100, 20, 30}
	name3["李四"] = [3]int{100, 20, 30}
	name3["王五"] = [3]int{100, 20, 30}
	name3["赵六"] = [3]int{100, 20, 30}
	name3["赵7"] = [3]int{100, 20, 30}
	name3["赵8"] = [3]int{100, 20, 30}
	name3["赵9"] = [3]int{100, 20, 30}
	fmt.Println(name3)
	fmt.Println(len(name3))
	//循环取值
	for k, v := range name3 {
		fmt.Println(k, v)

	}
	//循环存值
	for i := 0; i < 10; i++ {
		name4 := map[string][3]int{}
		name4["张三"] = [3]int{10, 20, 30}
		name4["李四"] = [3]int{10, 20, 30}
		name4["王五"] = [3]int{10, 20, 30}
		name4["赵六"] = [3]int{10, 20, 30}
		name4["赵7"] = [3]int{10, 20, 30}
		name4["赵8"] = [3]int{10, 20, 30}
		name4["赵9"] = [3]int{10, 20, 30}
		fmt.Println(name4)

	}

	name5 := map[int]string{}
	name5[1] = "1"
	name5[2] = "1"
	name5[3] = "1"
	//判断键值是否存在
	v, o := name5[1]
	fmt.Println(v, o)
	//删除
	delete(name5, 1)
	fmt.Println(name5)

}
